﻿#define _CRT_SECURE_NO_WARNINGS

//1.某大学的GPA(绩点)计算规则如下：
//课程百分制成绩90分对应绩点4.0，超过90分的，按90分计；如不足90分，则课程绩点 = 4.0 * 分数 / 90。
//学生综合绩点按该生已修的各门课程绩点结合学分加权平均而得。
//现有步步同学入学后的已修课程（共5门）成绩表如下，请编程计算其GPA

#include<stdio.h>

main()
{
    int score = 0, num = 0;
    int xf = 0;
    double GPA = 0, nG = 0;
    double aver = 0;
    for (int i = 1; i <= 5; i++)
    {
        scanf("%d %d", &score, &num);
        GPA = 4.0 * (score > 90 ? 90 : score) / 90 * num;
        xf += num;
        nG += GPA;
    }
    aver = nG / xf;
    printf("GPA:%.2lf", aver);
}

//2.本题要求编写程序，输入10个字符，统计其中英文字母、空格或回车、数字字符和其他字符的个数

#include<stdio.h>

main()
{
    char ch = 0;
    int letter = 0, blank = 0, digit = 0, other = 0;
    for (int i = 1; i <= 10; i++)
    {
        scanf("%c", &ch);
        if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
        {
            letter++;
        }
        else if (ch == 32 || ch == '\n')
        {
            blank++;
        }
        else if (ch >= '0' && ch <= '9')
        {
            digit++;
        }
        else
        {
            other++;
        }
    }
    printf("letter = %d, blank = %d, digit = %d, other = %d", letter, blank, digit, other);
}

//3.本题要求编写程序，计算序列部分和 1 - 1/4 + 1/7 - 1/10 + ... 直到最后一项的绝对值不大于给定精度eps

#include<stdio.h>
#include<math.h>

//fabs(__)取绝对值函数，需添加<math.h>头文件
main()
{
    double eps = 0, exam = 0, sum = 0;
    int fm = 1, fh = 1;
    scanf("%lf", &eps);
    do
    {
        exam = (1.0 / fm) * fh;
        fm += 3;
        fh = -fh;
        sum += exam;
    } while (fabs(exam) > eps);
    printf("sum = %.6lf", sum);
}

//4.本题要求对两个正整数m和n（m≤n）编写程序，计算序列和m^2+ 1 / m + (m + 1)^2+ 1 / (m + 1) + ⋯ + n^2+ 1 / n

#include<stdio.h>
#include<math.h>
main()
{
    int m = 0, n = 0;
    scanf("%d %d", &m, &n);
    double sum = 0;

    for (int i = m; i <= n; i++)
    {
        sum += pow(i, 2) + 1.0 / i;
    }

    printf("sum = %.6lf", sum);
}